from src.interviewer import InterViewer
from src.tools import Tools

def get_all_interviewer(cnx):
    '''
    不要随意动数据库中的数据
    :param cnx:
    :return:
    '''
    cur = cnx.cursor()
    cur.execute("select distinct username from zzxs_ftr;")
    return tuple(cur)


def get_statistics():
    tool = Tools()
    cnx = tool.get_mysql_connection()
    lists = get_all_interviewer(cnx)
    interviewers_sorted = {}
    for item in lists:
        interviewer = InterViewer(item[0], cnx)
        interviewers_sorted[item[0]]= interviewer.get_end_test_time()
    lists = sorted(interviewers_sorted,reverse=True)

    tool.clear()
    for item in lists:
        interviewer = InterViewer(item,cnx)
        try:
            tool.show(interviewer.get_statistics())
        except Exception as e:
            # print('the %s has no record!' % item)
            pass
    return tool.beautify_show()

if __name__ == '__main__':
    get_statistics()